<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <title th:text="${title}"></title>
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-4 col-md-4 col-lg-4 col-xl-4">
                <h5 th:text="'Welcome ' + ${username}"></h5>
            </div>
            <div class="col-sm-8 col-md-8 col-lg-8 col-xl-8">
                <h5>You have the following permissions: <mark th:text="${rights}"></mark></h5>
            </div>
        </div>
        <div class="row">
            <h5>Your Access Token is: <small th:text="${accesstoken}"></small></h5>
        </div>
        <div class="row">
            <div class="card col-sm-6 col-md-6 col-lg-6 col-xl-6">
                <div class="card-header">
                    <div class="input-group mb-3">
                        <input id="plaintext_in" type="text" class="form-control" placeholder="明文">
                        <div class="input-group-append">
                            <button class="btn btn-success" onClick="encrypt()">Encrypt</button>
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    <dl>
                        <dt>Result</dt>
                        <dd id="ciphertext_out"></dd>
                    </dl>
                </div>
            </div>
            <div class="card col-sm-6 col-md-6 col-lg-6 col-xl-6">
                <div class="card-header">
                    <div class="input-group mb-3">
                        <input id="ciphertext_in" type="text" class="form-control" placeholder="密文">
                        <div class="input-group-append">
                            <button class="btn btn-success" onClick="decrypt()">Decrypt</button>
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    <dl>
                        <dt>Result</dt>
                        <dd id="plaintext_out"></dd>
                    </dl>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript">
function encrypt(){
    $.ajax({
        url: '/conf/encrypt/',
        type: 'POST',
        contentType: "text/plain",
        data: document.getElementById("plaintext_in").value,
        success: function (data) {
            document.getElementById("ciphertext_out").innerHTML = data;
        },
        error: function (data) {
            document.getElementById("ciphertext_out").innerText = data.status + ":" + data.statusText;
        }
    });
};

function decrypt() {
    $.ajax({
        url: '/conf/decrypt/',
        type: 'POST',
        contentType: "text/plain",
        data: document.getElementById("ciphertext_in").value,
        success: function (data) {
            document.getElementById("plaintext_out").innerHTML = data;
        },
        error: function (data) {
            document.getElementById("plaintext_out").innerText = data.status + ":" + data.statusText;
        }
    });
}
</script>
</html>
